package com.wqm.step.pojo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "o_order")
public class Order implements Serializable{
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "oid")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	private Double money;

	private String address;

	@ManyToOne(targetEntity = Customer.class)// order为多方，所以是多对一
	@JoinColumn(name = "cid")// 指定外键列
	//@Cascade(CascadeType.SAVE_UPDATE)// 级联保存/更新，不清楚用法的人不要写在多方。
	//最好写在没有外键的一方，不要两边都写，第一、这样会增加数据库的update语句，影响性能。
	//									   第二、如果级联删除，不至于删除过多，当然现实开发中，一般不使用级联删除
	// 记住：哪边配置了级联，在session.save/update/delete(传入哪边的对象)
	private Customer c;

	public Order() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Double getMoney() {
		return money;
	}

	public void setMoney(Double money) {
		this.money = money;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Customer getC() {
		return c;
	}

	public void setC(Customer c) {
		this.c = c;
	}

	/**
	 *  重写toString，要去掉Customer的对象，保证在调用toString()的时候不会陷入死循环
	 *  一对多，两边的实体类toString都要修改
	 */
	/*@Override
	public String toString() {
		return "Order [id=" + id + ", money=" + money + ", address=" + address + ", c=" + c + "]";
	}*/
	@Override
	public String toString() {
		return "Order [id=" + id + ", money=" + money + ", address=" + address + "]";
	}
	
}
